package com.sunqizhong.controller;

import com.github.pagehelper.Page;
import com.sunqizhong.entity.*;
import com.sunqizhong.mapper.ClazzsMapper;
import com.sunqizhong.service.ClazzsService;
import com.sunqizhong.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.awt.event.WindowFocusListener;
import java.util.Arrays;
import java.util.List;

@Slf4j
@RestController
public class StudentController {

    @Autowired
    private StudentService studentService;

    /*
    * 员工列表查询
    * */
/*    @GetMapping("/students")
    public Result page(@RequestParam(defaultValue = "1") Integer page,
                               @RequestParam(defaultValue = "10") Integer pageSize){
        log.info("查询员工信息,page={},pageSoze={}",page,pageSize);
        PageBean pageBean = studentService.page(page,pageSize);
        return Result.success(pageBean);
    }*/
    @GetMapping("/students")
    public Result page(Student param){
        log.info("请求参数：{}",param);
        PageBean pageBean = studentService.page(param);
        return Result.success(pageBean);
    }

    /*
    * 添加学员
    * */
    @PostMapping("/students")
    public Result save(@RequestBody Student student){
        log.info("请求参数student:{}",student);
        studentService.save(student);
        return Result.success();
    }

    /*
    * 批量删除学员
    * */
    @DeleteMapping("/students/{ids}")
    public Result delete(Integer[] ids){
        log.info("批量删除部门：ids={}", Arrays.asList(ids));
        studentService.deleteByIds(ids);
        return Result.success();
    }
}
